﻿#ifndef _MAIN_EDITOR_H_INCLUDE_
#define _MAIN_EDITOR_H_INCLUDE_

#include "common.h"
#include "wx/stc/stc.h"  

class MainScriptEditor : public wxStyledTextCtrl
{
public:
    MainScriptEditor(wxWindow* parent, wxWindowID id = wxID_ANY,
		const wxPoint& pos = wxDefaultPosition,
		const wxSize& size = wxDefaultSize,
		long style = wxVSCROLL);
    ~MainScriptEditor();

    inline void setAuiNotebook(wxAuiNotebook *notebook) { m_mainAuiNotebook = notebook; }
    inline void setCurrentOperatorFile(wxString file) { m_currentOperatorFile = file; }
    inline wxString getCurrentOperatorFile(void) { return m_currentOperatorFile; }
	bool LoadFile(const wxString& filename);
    bool SaveFile(void);

protected:
	void OnSize(wxSizeEvent& event);

private:
    void HighlightAllMatches(const wxString& text);
    void ClearAllHighlights();
    void OnContentChange(wxStyledTextEvent& event);
    void OnStyledTextModified(wxStyledTextEvent& event);
    void OnSelectionChanged(wxStyledTextEvent& event);
    void OnCharAdded(wxStyledTextEvent& event);
    void OnMarginClick(wxStyledTextEvent& event);
    void OnAutocompCancelled(wxStyledTextEvent& event);
    void OnAutocompSelectionChange(wxStyledTextEvent& event);
    void OnMouseMove(wxMouseEvent& event);
    void OnHoverTimer(wxTimerEvent& event);
    void OnLeftDoubleClick(wxMouseEvent& event);
    void SetupLuaSyntaxHighlight(void);
    wxString LoadGB2312File(const wxString& filename);
    bool SaveGB2312File(const wxString& filename,wxString content);

    void InitLuaEditorWithFolding(wxStyledTextCtrl* ctrl);
    void SetLuaFoldLevels(wxStyledTextCtrl* ctrl);
    void SetupLuaFolding(wxStyledTextCtrl* ctrl);

private:
    wxString m_contentMd5Value;
    wxString m_currentOperatorFile;                /**< 当前操作的文件 */
    wxAuiNotebook *m_mainAuiNotebook;
    wxTimer m_hoverTimer;
    wxString m_currentHoverString;
    int m_lastModifiedLine;
    bool m_isTextModified;
    bool m_isLeftBtnDoublieClick;

	wxDECLARE_EVENT_TABLE();
};

#endif
